<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script>
   $(document).ready(function(){
	   if ($("#id").val()!=null&&$("#id").val()!=0) {
		$("#itemCode").attr("disabled","disabled");
		}
	   $("#itemCategory").select2();
	   $("#itemkbn").select2();
	   $("#backBtn").click(function(){
           $("#showHtml").removeClass("showHtml");
           $("#confirmPage").css("display","none");
           $("#editPage").css("display","block");
           $("#showHtml").find("input").removeAttr("disabled");
           $("#showHtml").find("select").removeAttr("disabled");
           $("#showHtml").find("textarea").removeAttr("disabled");
           return false;
       });
	}); 
    
    //保存方法
    var checkForm={
            t:null,
            check:function(t){
                $(t).attr("disabled",true);
                this.t=t;	
                $("#inputForm").validate({
                   
                    // 重名验证
                    rules: {
                    itemCode: {remote: "${ctx}/finance/subject/checkName?itemCategory=" +$("#itemCategory").val() },
                    },
                    messages: {
                     //数据值以存在
                     itemCode: {remote: '<spring:message code="codeuser_exits"/>'},
                    },
                    fail: function(element,e) {  
                         $(saveForm.t).attr("disabled",false);
                    },
                    
                    submitHandler: function(form) {
   	                 $("#showHtml").addClass("showHtml");
   	                 $("#confirmPage").css("display","block");
   	                 $("#editPage").css("display","none");
   	                 $(checkForm.t).attr("disabled",false);
   	              $("#showHtml").find("input").attr("disabled","disabled");
   	              $("#showHtml").find("select").attr("disabled","disabled");
   	              $("#showHtml").find("textarea").attr("disabled","disabled");
                    }
                });
                
                // 提交表单
                $("#inputForm").submit(); 
            }
    }
    
    var saveForm={
    		s:null,
            t:null,
            save:function(s,t){
                $(t).attr("disabled",true);
                this.s=s;
                this.t=t;
                // 格式化，去除逗号
           $("#showHtml").find("input").removeAttr("disabled");
           $("#showHtml").find("select").removeAttr("disabled");
           $("#showHtml").find("textarea").removeAttr("disabled");
                formUnFormat($("#inputForm"));
         	    var params = $("#inputForm").serialize();
                $.post("${ctx}/finance/subject/save",params,function(result){
               	 // 提示信息
                    tipParent(result.message);
                    // 返回状态
                    if(result.statusCode==STATUSCODEOK){
                        if(saveForm.s==1){

                         // 刷新页面
                            window.parent.frames[0].searchListForm();
                            /* addItemValue(); */
                            
                        }else{
                            window.parent.frames[0].searchListForm();
                            closeWin(); 
                        }
                      }else{
                          $(saveForm.t).attr("disabled",false);
                      }
                },'json');
            } 
       }
   
    </script> 
    </head>
	<body>
	<!-- 创建页面head部 -->
	<div id="editPage" class="layerHeader clearfix">
	
		<c:choose>
	        <c:when test="${dict.id!=null && dict.id!=''}">
	             <!-- 修改编辑 -->
	            <p class="headerTitle"><spring:message code="dict_modifyDict"/></p>
	        </c:when>
	        <c:otherwise>
	             <!-- 新建 -->
	            <p class="headerTitle"><spring:message code="dict_createAccount"/></p>
	        </c:otherwise>
	    </c:choose>

	    <div class="headerButton clearfix">
	    <shiro:hasPermission name="finance:subject:edit">
	       <button type="button" id="confirmBtn" onclick="checkForm.check(0,this)"><spring:message code="btn_ok"/></button>
	    </shiro:hasPermission>
	       <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
	
	<!-- 确认页面head部 -->
	<div id="confirmPage" class="layerHeader clearfix" style="display:none">
		<p class="headerTitle"><spring:message code="confirmation_of_accounts"/></p>
	    <div class="headerButton clearfix">
	        <shiro:hasPermission name="finance:subject:edit">
	        <button type="button" id="saveBtn" onclick="saveForm.save(0,this)"><spring:message code="common_save"/></button>
 			</shiro:hasPermission>
	        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
    <form id="inputForm" method="post" >
    <input type="hidden" id="id" name="id" value="${finance.id}"/>
<div id="showHtml">
	<div class="smList">
	        <div class="items clearfix" >
	        	<div class="col-50 clearfix haveToBox" >
	        		<!-- 科目代码 -->   
	                <p class="tit"><spring:message code="account_code" /></p>
					<input  id="itemCode" name="itemCode" value="${finance.itemCode}" onblur="changeItemCode()" data-rule-required="true" data-msg-required="<spring:message code="dict_pleaseInputCode"/>" 
					data-rule-lettersnumbers="true"  data-msg-lettersnumbers="<spring:message code="dict_pleaseInputCode"/>">
					<p class="haveTo">*</p>
	            </div>            
	        </div>

	        <div class="items clearfix">
	        	<div class="col-50 clearfix haveToBox">
	        		<!-- 科目名称 -->
	                <p class="tit"><spring:message code="course_title" /></p>
	                <input id="itemName" name="itemName" value="${finance.itemName}" data-rule-required="true" data-msg-required="<spring:message code="dict_pleaseInputTitleCode"/>">
	                <p class="haveTo">*</p>
	            </div>
	        </div>

	        <div class="items clearfix">
	        <c:set value="FINANCELIST" var="financeList" />
						<div class="col-50 clearfix haveToBox">
	        		<!-- 科目类别 -->
						<p class="tit"><spring:message code="account_category" /></p>
						<select class="w-styleCategory" id="itemCategory" name="itemCategory" style="width: 150px" data-rule-required="true" data-msg-required="<spring:message code="account_category"/>">
							<option value=""><spring:message code="order_please_choose" /></option>
							<c:forEach items="${fns:getDictList(financeList)}" var="item">
								<option  value="${item.itemCode}-${item.itemValue}" <c:if test="${fn:split(finance.itemCategory,'-')[1] eq item.itemValue }">selected="selected"</c:if>>${item.itemName}</option>
							</c:forEach>
						</select>
						<p class="haveTo">*</p>
	           </div>
	        </div>
	        <div class="items clearfix">
	        <c:set value="FINANCELISTTO" var="financelistto" />
	        	<div class="col-50 clearfix haveToBox">
	        		<!-- 借贷方 -->
	                <p class="tit"><spring:message code="reversal_of_entries" /></p>
	                	<select class="w-styleCategory" id="itemkbn"
							name="itemkbn" style="width: 150px" data-rule-required="true" data-msg-required="<spring:message code="reversal_of_entries"/>">>
							<option value=""><spring:message code="order_please_choose" /></option>
							<c:forEach items="${fns:getDictList(financelistto)}" var="item">
								<option value="${item.itemCode}-${item.itemValue}" <c:if test="${fn:split(finance.itemkbn,'-')[1] eq item.itemValue }">selected="selected"</c:if>>${item.itemName}</option>
							</c:forEach>
						</select>
						<p class="haveTo">*</p>
	            </div>
	        </div>
	        <div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--状态-->
					<p class="tit"><spring:message code="dict_state" /></p>
					<div class="labelBox">
						<!--启用-->
						<label> <input type="radio" name="enableFlag"
							checked='checked' value="1"
							<c:if test="${dict.enableFlag eq 1}">checked="checked"</c:if>
							class="rast" /> <spring:message code="dict_enable" /> 
						</label>
						<!--停用-->
						<label><input type="radio" name="enableFlag" value="0"
							<c:if test="${dict.enableFlag eq 0}">checked="checked"</c:if>
							class="rast" /> <spring:message code="dict_disable" /> 
						</label>
					</div>
	            </div>
	        </div>
	        <div class="items clearfix">
		       <!-- 描述 -->
               <p class="tit"><spring:message code="dict_remarks"/>(0/100)</span></p>
               <textarea style="width:400px;height: 140px" name="remarks"  value="${finance.remarks}">${finance.remarks}</textarea>
		    </div> 
	        
	</div>
</div>
</form>
</body>
</html>